/**
 * 3Dify 1.1 - 2014-04-20
 * Copyright (c) 2010 Serafino Bilotta (serafinobilotta@hotmail.com - http://www.p2warticles.com)
 *  *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * More information on this project:
 * http://www.p2warticles.com/
 *
 * Requires: jQuery v1.3+
 *
 * Full Usage Documentation: http://www.p2warticles.com/2011/04/3dify-plugin/
 * Usage:
 *        $(el).threedify({
 *	 		posZ: value,		tilt of element, default 0
 *	 		angle: value		angle of perspective, default 15
 *		});
 *
 */

(function ($) {
    $.fn.threedify = function (op) {
        var defaults = {
            posZ: 0,
            angle: 15
        };
        var options = $.extend(defaults, op);

        return this.each(function () {

            $(this).mousemove(function (e) {
                var posX = (0.50 - (e.layerX) / $(e.currentTarget).width()) * 2 * options.angle,
                    posY = (-0.50 + (e.layerY) / $(e.currentTarget).height()) * 2 * options.angle;
                var cssObj = {
                    '-o-transform': 'rotateX(' + posY + 'deg) rotateY(' + posX + 'deg) rotateZ(' + options.posZ + 'deg)',
                    '-ms-transform': 'rotateX(' + posY + 'deg) rotateY(' + posX + 'deg) rotateZ(' + options.posZ + 'deg)',
                    '-moz-transform': 'rotateX(' + posY + 'deg) rotateY(' + posX + 'deg) rotateZ(' + options.posZ + 'deg)',
                    '-webkit-transform': 'rotateX(' + posY + 'deg) rotateY(' + posX + 'deg) rotateZ(' + options.posZ + 'deg)',
                    'transform': 'rotateX(' + posY + 'deg) rotateY(' + posX + 'deg) rotateZ(' + options.posZ + 'deg)'
                };
                $(this).css(cssObj);
            });

        });
    };
})(jQuery);